package com.changpay.zywy.ui.activity.loan

import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.changpay.zywy.R
import com.changpay.zywy.adapter.DaiLiAdapter
import com.changpay.zywy.adapter.ProjectLoanAdapter
import com.changpay.zywy.app.App.Companion.context
import com.changpay.zywy.base.BaseActivity
import com.changpay.zywy.base.IView
import com.changpay.zywy.bean.DaiLiBean
import com.changpay.zywy.bean.ProjectBean
import com.changpay.zywy.ext.sss
import com.changpay.zywy.http.RetrofitHelper
import kotlinx.android.synthetic.main.activity_recycle.*
import kotlinx.android.synthetic.main.title_layout.*

class LoanSecondActivity : BaseActivity(), IView {

    private var type: Int = 0
    private var positionData: ProjectBean? = null


    override fun showLoading() {
    }

    override fun hideLoading() {

    }

    override fun showDefaultMsg(msg: String) {
    }

    override fun showMsg(msg: String) {
    }

    override fun showError(errorMsg: String) {
    }

    override fun attachLayoutRes(): Int {
        return R.layout.activity_recycle
    }

    override fun initData() {
    }

    override fun initView() {
        tv_title.text = "选择项目名称"
        iv_back.setOnClickListener { finish() }
        initRecyclerView()
    }

    override fun start() {
        loadData()
    }

    private fun loadData() {
        // 加载底部数据
        val param = hashMapOf<String, String>()
        param["key"] = token
        if (this.type == 0) {
            RetrofitHelper.service.get_goodsClass_list(param).sss(this) {
                datas_one.addAll(it.result)
//                mAdapter_one.addData(it.result)
                mAdapter_one.notifyDataSetChanged()
            }
        }
//        else {
//            RetrofitHelper.service.get_mb_list(param).sss(this) {
//                mAdapter_two.run {
//                    bindToRecyclerView(recyclerView)
//                    onItemChildClickListener = this@LoanSecondActivity.onItemChildClickListener
//                    onItemClickListener = this@LoanSecondActivity.ItemClickListener
//                }
//                datas_two.addAll(it.result)
//                mAdapter_two.notifyDataSetChanged()
//            }
//        }
    }


    /**
     * datas
     */
    private val datas_one = mutableListOf<ProjectBean>()
    /**
     * datas
     */
    private val datas_two = mutableListOf<DaiLiBean>()


    /**
     * Adapter
     */
    private val mAdapter_one: ProjectLoanAdapter by lazy {
        ProjectLoanAdapter(context, datas_one)
    }

    /**
     * Adapter
     */
    private val mAdapter_two: DaiLiAdapter by lazy {
        DaiLiAdapter(context, datas_two)
    }


    /**
     * LinearLayoutManager
     */
    private val linearLayoutManager: LinearLayoutManager by lazy {
        LinearLayoutManager(context)
    }


    /**
     * ItemClickListener
     */
    private val ItemClickListener = BaseQuickAdapter.OnItemClickListener { _, _, position ->
//        if (type == 0) {
//            positionData = datas_one[position]
//            this.type = 1
//            loadData()
//        } else {
            val intent = Intent()
            intent.putExtra("gc_name", datas_one[position].gc_name)
//            intent.putExtra("member_name", datas_two[position].member_name)
//            intent.putExtra("member_phone",  datas_two[position].member_mobile)
//            intent.putExtra("member_id",  datas_two[position].member_id.toString())
            intent.putExtra("gc_id", datas_one[position].gc_id.toString())
            setResult(500, intent)
            finish()
//        }
    }


    /**
     * ItemChildClickListener
     */
    private val onItemChildClickListener = BaseQuickAdapter.OnItemChildClickListener { _, view, position ->
        when (view.id) {
        }
    }

    private fun initRecyclerView() {
        recyclerView.run {
            layoutManager = linearLayoutManager
            adapter = mAdapter_one
//            itemAnimator = DefaultItemAnimator()
//            recyclerViewItemDecoration.let { addItemDecoration(it) }
        }
        mAdapter_one.run {
            bindToRecyclerView(recyclerView)
            onItemChildClickListener = this@LoanSecondActivity.onItemChildClickListener
            onItemClickListener = this@LoanSecondActivity.ItemClickListener
        }



    }

}